package com.ruoyi.project.fit.controller;


import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.fit.domain.Cost;
import com.ruoyi.project.fit.domain.FitDept;
import com.ruoyi.project.fit.service.CostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/fit/cost")
public class CostController extends BaseController {

    @Autowired
    private CostService costService;


    /**
     * 删除检查费用
     */
    @PreAuthorize("@ss.hasPermi('fit:cost:remove')")
    @Log(title = "检查费用", businessType = BusinessType.DELETE)
    @DeleteMapping("/{costIds}")
    public AjaxResult remove(@PathVariable Long[] costIds) {

        return toAjax(costService.deleteCostByIds(costIds));
    }

    /**
     * 修改检查费用
     */
    @PreAuthorize("@ss.hasPermi('fit:cost:edit')")
    @Log(title = "检查费用", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody Cost cost) {

        cost.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(costService.updateCost(cost));
    }
    /**
     * 新增定时任务
     */
    @PreAuthorize("@ss.hasPermi('fit:cost:add')")
    @Log(title = "检查费用", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody Cost cost) {
        cost.setCreateBy(SecurityUtils.getUsername());
        return toAjax(costService.insertCost(cost));
    }

    /**
     * 根据费用编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('fit:cost:query')")
    @GetMapping(value = "/{costId}")
    public AjaxResult getInfo(@PathVariable Long costId) {
        return AjaxResult.success(costService.selectCostById(costId));
    }
    /**
     * 获取检查费用列表
     */
    @PreAuthorize("@ss.hasPermi('fit:cost:list')")
    @GetMapping("/list")
    public TableDataInfo list(Cost cost) {
        startPage();
        List<Cost> list = costService.selectCostList(cost);
        return getDataTable(list);
    }

}
